package org.mch.func.m_px.yunsf;

import java.awt.BorderLayout;
import java.awt.Font;

import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;

import org.mch.biz.ui.FuncEvent;
import org.mch.biz.ui.FuncPanel;
import org.mch.swingm.core.MToggleButton;

/**
 * 描述：Java运算符演练；<BR/>
 * 
 * @author ZL；<BR/>
 *
 *         参考：MCHWEB.NET；<BR/>
 *
 */
public class YunSFPanel extends FuncPanel {
	private static final long serialVersionUID = 7436929897080596483L;

	private MToggleButton[] btnSorts;
	private JTabbedPane tabbedPane;
	private JPanel panelAnWeiQuFan;
	private AnWeiYiHuo_Panel panelAnWeiYiHuo;
	private AnWeiZuoYouYi_Panel panelAnWeiZuoYouYi;
	private ErJinZhiJiSuan_Panel panelErJinZhiJiSuan;
	private JPanel panel_about;
	private JScrollPane scrollPane;
	private JEditorPane editorPane;

	public YunSFPanel() {
		super();
		setLayout(new BorderLayout(0, 0));
		add(getTabbedPane(), BorderLayout.CENTER);
	}

	@Override
	protected FuncEvent createEvent() {
		return new YunSFEvent(this);
	}

	public MToggleButton[] getBtnSorts() {
		return btnSorts;
	}

	public void setBtnSorts(MToggleButton[] btnSorts) {
		this.btnSorts = btnSorts;
	}

	public JTabbedPane getTabbedPane() {
		if (tabbedPane == null) {
			tabbedPane = new JTabbedPane(JTabbedPane.TOP);
			tabbedPane.setFont(new Font("宋体", Font.PLAIN, 13));
			tabbedPane.addTab("~ 按位取反", null, getPanelAnWeiQuFan(), null);
			tabbedPane.addTab("^ 按位异或", null, getPanelAnWeiYiHuo(), null);
			tabbedPane.addTab(">> << >>> 按位左移右移", null, getPanelAnWeiZuoYouYi(), null);
			tabbedPane.addTab("二进制计算", null, getPanelErJinZhiJiSuan(), null);
			tabbedPane.addTab("原码、反码、补码说明", null, getPanel_about(), null);
		}
		return tabbedPane;
	}

	public JPanel getPanelAnWeiQuFan() {
		if (panelAnWeiQuFan == null) {
			panelAnWeiQuFan = new AnWeiQuFan_Panel();
		}
		return panelAnWeiQuFan;
	}

	public JPanel getPanelAnWeiYiHuo() {
		if (panelAnWeiYiHuo == null) {
			panelAnWeiYiHuo = new AnWeiYiHuo_Panel();
		}
		return panelAnWeiYiHuo;
	}

	public JPanel getPanelAnWeiZuoYouYi() {
		if (panelAnWeiZuoYouYi == null) {
			panelAnWeiZuoYouYi = new AnWeiZuoYouYi_Panel();
		}
		return panelAnWeiZuoYouYi;
	}

	public JPanel getPanel_about() {
		if (panel_about == null) {
			panel_about = new JPanel();
			panel_about.setLayout(new BorderLayout(0, 0));
			panel_about.add(getScrollPane(), BorderLayout.CENTER);
		}
		return panel_about;
	}

	public JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setViewportView(getEditorPane());
		}
		return scrollPane;
	}

	public ErJinZhiJiSuan_Panel getPanelErJinZhiJiSuan() {
		if (panelErJinZhiJiSuan == null) {
			panelErJinZhiJiSuan = new ErJinZhiJiSuan_Panel();
		}
		return panelErJinZhiJiSuan;
	}

	public JEditorPane getEditorPane() {
		if (editorPane == null) {
			editorPane = new JEditorPane();
			editorPane
					.setText("1. 原码\r\n\r\n原码就是符号位加上真值的绝对值, 即用第一位表示符号, 其余位表示值. 比如如果是8位二进制:\r\n\r\n[+1]原 = 0000 0001\r\n\r\n[-1]原 = 1000 0001\r\n\r\n第一位是符号位. 因为第一位是符号位, 所以8位二进制数的取值范围就是:\r\n\r\n[1111 1111 , 0111 1111]\r\n\r\n即\r\n\r\n[-127 , 127]\r\n\r\n原码是人脑最容易理解和计算的表示方式.\r\n\r\n2. 反码\r\n\r\n反码的表示方法是:正数的反码是其本身\r\n\r\n负数的反码是在其原码的基础上, 符号位不变，其余各个位取反.\r\n\r\n[+1] = [00000001]原 = [00000001]反\r\n\r\n[-1] = [10000001]原 = [11111110]反\r\n\r\n可见如果一个反码表示的是负数, 人脑无法直观的看出来它的数值. 通常要将其转换成原码再计算.\r\n\r\n3. 补码\r\n\r\n补码的表示方法是:\r\n\r\n正数的补码就是其本身\r\n\r\n负数的补码是在其原码的基础上, 符号位不变, 其余各位取反, 最后+1. (即在反码的基础上+1)\r\n\r\n[+1] = [00000001]原 = [00000001]反 = [00000001]补\r\n\r\n[-1] = [10000001]原 = [11111110]反 = [11111111]补\r\n\r\n对于负数, 补码表示方式也是人脑无法直观看出其数值的. 通常也需要转换成原码在计算其数值.");
			editorPane.setFont(new Font("宋体", Font.PLAIN, 12));
		}
		return editorPane;
	}

}
